# -*- coding: utf-8 -*-
# __author__ = 'xxx'
# env:  python 3.6+  plac 1.3.5 pytz 2022.7.1 certifier 0.2.1
# <https://github.com/zopyx/ssl-cert-check>
# fuction:  检查 站点过期时间

import certifier,time
from  email import utils
from datetime import datetime
import  pytz,plac


def getexprieforssl(host,port=443):

    #获取当前时间 datetime
    getnow=datetime.utcnow().replace(tzinfo=pytz.utc)

    try:
        if host==None or host=='':
            print("请检查主机输入是否正确")
            return
        #获取证书过期时间
        cerinfo=certifier.CertInfo(host,port)

    except Exception as e:
        print(f" host error {host} ")
        return

    expre=cerinfo.expire()

    #字符串转换成datetime
    expday=utils.parsedate_to_datetime(expre)

    outday=(expday - getnow).days
    print(f" host: {host}  证书还有 {outday} 天过期 ")


if __name__ == '__main__':
    plac.call(getexprieforssl)

